<!DOCTYPE html>
<html lang="en">
<!--头部信息-->
<head>
    <meta charset="utf-8">
    <title>受刑现场</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">

    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
</head>
<!--受刑现场-->
<body>
<div class="layuimini-container">
    <div class="layuimini-main">


        <!--搜索框-->
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item common" id="seach">


                        <!--姓名-->
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" id="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!--地狱层级-->
                        <div class="layui-inline">
                            <label class="layui-form-label required">地狱层级</label>
                            <div class="layui-input-block" style="width: 65%">
                                <select name="dycj" id="dycj">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>


                        <!--搜索按钮-->
                        <div class="layui-inline" style="padding-left: 5px">
                            <button class="layui-btn layui-btn-primary" data-type="reload" id="search"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>


                    </div>
                </div>
            </div>
        </fieldset>

        <!--表头操作-->
        <script type="text/html" id="toolbarDemo">
        </script>


        <!--创建表格-->
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


        <!--表内操作-->
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">提前释放</a>
        </script>


    </div>
</div>
<script>
    layui.use(['form', 'table', 'jquery', 'layer', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            table = layui.table;

        getDycj();

        /*初始化【地狱】下拉列表框*/
        function getDycj() {
            $.ajax({
                type: 'GET',
                url: '/getEighteenLevel',
                dataTypel: 'json',
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        $("#dycj").append("<option value=\"" + data[i].level + "\">" + data[i].eightName +
                            "</option>");
                        $("#dycj").val("");
                    }
                    layui.form.render("select");
                }
            })
        }


        /*表格数据渲染*/
        table.render({
            elem: '#currentTableId',
            url: '/getXfxcList',
            toolbar: '#toolbarDemo',
            cellMinWidth: 50,
            height: 440,
            limit: 8,
            limits: [8, 16, 24, 32, 40],
            method: 'GET',
            text: {
                none: '暂时没有数据哦！'
            },
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '刑罚现场数据',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {type: 'numbers', width: 50, title: '序号', align: "center"}
                    , {field: 'xid', hide: true, width: 80, title: '主ID', sort: true, align: "center"}
                    , {field: 'xuserId', hide: true, title: 'ID', sort: true, align: "center"}
                    , {field: 'xuserName', title: '姓名', align: "center"}
                    , {
                    field: 'xdycj', title: '地狱层级', align: "center", templet: function (d) {
                        return "第" + d.xdycj + "层";
                    }
                }
                    , {field: 'xcjsj', hide: true, title: '创建时间', sort: true, align: "center"}
                    , {
                    field: 'xsxsj', title: '受刑时间', sort: true, align: "center", templet: function (d) {
                        return d.xsxsj += "年";
                    }
                }
                    , {field: 'xontime', title: '入狱时间', sort: true, align: "center"}
                    , {fixed: 'right', title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                ]
            ],
            page: true,
            id: "testId"
        });


        /*搜索事件处理*/
        $('#search').click(function () {
            var username = $('#username').val(),
                level = $("#dycj").val();
            /*表格重载*/
            table.reload('testId', {
                page: {
                    curr: 1
                },
                where: {
                    username: username,
                    level: level
                }
            }, 'data');
        });


        /*表内操作事件处理*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var n = data.xuserName;
            if (obj.event === 'edit') {
                layer.confirm('确定提前释放' + data.xuserName + '吗？', {icon: 3}, function (index) {
                    /*删除请求*/
                    $.ajax({
                        type: 'DELETE',
                        url: '/updateXf/' + data.xid,
                        dataType: 'text',
                        error: function () {
                            layer.alert('系统错误！');
                        },
                        success: function (result) {
                            if (result === "success") {
                                layer.alert('提前释放' + n + '成功！',
                                    {
                                        title: '成功',
                                        skin: 'layui-layer-molv',
                                        btn: ['返回'],
                                        anim: 1,
                                        icon: 6,
                                        yes: function (index, layero) {
                                            obj.del();
                                            table.reload('testId', {
                                                page: {
                                                    curr: 1
                                                },
                                            });
                                            layer.close(index);
                                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                                        }
                                    });
                            } else {
                                layer.alert('提前释放失败，继续吗？',
                                    {
                                        title: '错误',
                                        skin: 'layui-layer-molv',
                                        btn: ['重试'],
                                        anim: 1,
                                        icon: 5,
                                        yes: function (index) {
                                            layer.close(index);
                                        }
                                    });
                            }
                        }
                    });
                });
            }
        });
    });
</script>

</body>
</html>